{include file='public/header' /}
<!-- 正文开始 -->
<div class="layui-card">

    <div class="layui-card-body">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
                <li  class="layui-this" >自动回复消息配置</li>
                <li  >首次回复消息配置</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item  layui-show ">
                    <form class="layui-form">
                        <input type="hidden" name="id" value="{$row.id}">
                        <div class="layui-form-item">
                            <label for="" class="layui-form-label" style="width: 120px">是否开启自动回复</label>
                            <div class="layui-input-inline" style="min-width: 600px">
                                <input type="radio" name="message_state" value="1" {if 1==$row.message_state} checked {/if} title="开启">
                                <input type="radio" name="message_state" value="2" {if 2==$row.message_state} checked {/if} title="关闭">

                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>

                        <div class="layui-form-item">
                            <label for="" class="layui-form-label" style="width: 120px">自动回复内容</label>
                            <div class="layui-input-inline" style="min-width: 600px;">
                                <textarea name="message" lay-verify="content" style="width: 280px;height: 80px;"  class="field-content" id="">{$row.message}</textarea>
                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="submit" class="layui-btn {:auth('system.message/edit')}" lay-submit lay-filter="config_group">确 认</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="layui-tab-item  ">
                    <form class="layui-form">
                        <input type="hidden" name="id" value="{$row.id}">
                        <div class="layui-form-item">
                            <label for="" class="layui-form-label" style="width: 120px">是否开启首次回复</label>
                            <div class="layui-input-inline" style="min-width: 600px">
                                <input type="radio" name="first_message_state" value="1" {if 1==$row.first_message_state} checked {/if} title="开启">
                                <input type="radio" name="first_message_state" value="2" {if 2==$row.first_message_state} checked {/if} title="关闭">

                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>

                        <div class="layui-form-item">
                            <label for="" class="layui-form-label" style="width: 120px">首次回复内容</label>
                            <div class="layui-input-inline" style="min-width: 600px;">
                                <textarea name="first_message" lay-verify="content" style="width: 280px;height: 80px;"  class="field-content" id="">{$row.first_message}</textarea>
                            </div>
                            <div class="layui-form-mid layui-word-aux"></div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="submit" class="layui-btn {:auth('system.message/edit')}" lay-submit lay-filter="config_group">确 认</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>

    </div>
</div>
<!-- js部分 -->
{include file='public/footer' /}
<script>
    layui.use(['layer', 'table', 'form','admin','upload','element','layedit'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var table = layui.table;
        var upload = layui.upload;

        var layedit = layui.layedit;
        layedit.set({
            uploadImage:{
                url:'{:__url("admin/upload/upload")}'//接口url
                ,type:''//默认post
            }});

        var login = layedit.build('login'); // 建立编辑器
        var pay = layedit.build('pay'); // 建立编辑器
        var privacy = layedit.build('privacy'); // 建立编辑器

        //图片
        $(".uploadPic").each(function (index,elem) {
            upload.render({
                elem: $(elem)
                ,url: '{{ route("api.upload") }}'
                ,multiple: false
                ,data:{"_token":"{{ csrf_token() }}"}
                ,done: function(res){
                    //如果上传失败
                    if(res.code == 0){
                        layer.msg(res.msg,{icon:1},function () {
                            $(elem).parent('.layui-upload').find('.layui-upload-box').html('<li><img src="'+res.url+'" /><p>上传成功</p></li>');
                            $(elem).parent('.layui-upload').find('.layui-upload-input').val(res.url);
                        })
                    }else {
                        layer.msg(res.msg,{icon:2})
                    }
                }
            });
        })
        // 添加按钮点击事件
        $('#btnAddRole').click(function () {
            showEditModel('新增',"{{route('admin.configuration.create')}}");
        });
        // 显示表单弹窗
        function showEditModel(title,url) {
            layer.full(admin.open({
                type: 2,

                title: title,
                content: url,
                btn:['提交','取消'],
                btnAlign: 'c',   // 按钮居中
                success: function (layero, dIndex) {
                    form.render();    // 表单渲染
                },

                yes: function (index, layero) {

                    // 获取弹出层中的form表单元素
                    var formSubmit=layer.getChildFrame('form', index);
                    //获取表单数据
                    var data = {dosubmit:1};
                    var action = formSubmit[0]['action'];
                    var a = formSubmit.serializeArray();
                    $.each(a, function () {
                        if (data[this.name] !== undefined) {
                            if (!data[this.name].push) {
                                data[this.name] = [data[this.name]];
                            }
                            data[this.name].push(this.value || '');
                        } else {
                            data[this.name] = this.value || '';
                        }
                    });

                    if (data.parent_id == '') {
                        data.parent_id = '0';
                    }

                    layer.load(2);
                    $.post(action, data, function (res) {
                        layer.closeAll('loading');
                        if (res.code == 0) {
                            layer.msg(res.msg, {icon: 1});
                            layer.close(index);

                            dataTable()

                        } else {
                            layer.msg(res.msg, {icon: 2});
                        }
                    }, 'json');

                    return false;

                },
                btn2: function (index, layero) {
                    layer.close(index);
                }


            }));
        }
        //提交
        form.on('submit(config_group)',function (data){
            var parm = data.field;
            parm['_method'] = 'put';
            var load = layer.load();
            data.field['privacy'] = layedit.getContent(privacy);
            data.field['pay'] = layedit.getContent(pay);
            data.field['login'] = layedit.getContent(login);
            $.post("{:__url('system.message/edit')}",data.field,function (res) {
                layer.close(load);
                if (res.code==0){
                    layer.msg(res.msg,{icon:1})
                }else {
                    layer.msg(res.msg,{icon:2});
                }
            });
            return false;
        });
    })
</script>

</body>
</html>
